<script language="javascript" type="text/javascript">
    $(window).scroll(
    function()
    {
        scrollTop = $(window).scrollTop();
        docHeight = getDocHeight();
        winHeight = getWinHeight();
        scrolltop20 = Math.round((getDocHeight() - getWinHeight())*0.9);
        result = getDocHeight() - getWinHeight();
		
        console.log('Top Scroll: '+ scrollTop +' || Win Height: '+ winHeight +' || Doc Height: '+ docHeight+' || scrolltop20: '+scrolltop20+' || result :'+ result );
	
        if($(window).scrollTop() >= scrolltop20)
        {
            if(killScroll == false) 
            {
                killScroll = true;
				
                $('#loading').show();
                $('#loadding-text').show();			
                $('#loading').html('<img src="images/loading.gif" alt="" width="150" height="13" />');

                if($("li:last").data('ctype') == 'newsSearch')
                {
                    newSearch('newsSearch', $("li:last").data('wordsearch'), $('li:last').data('newstype')); 
                }
                setTimeout(function(){killScroll = false},500);	
            }
        }
    }
); 
</script>
<br/><br/><br/>

<!-- Start of Search New page -->
<div data-role="page" id="searchMarket">
    <div data-role="header">
        <h1>ผลการค้นหา</h1>
        <a rel="external" id="link_web" href="?q=news" data-icon="back" data-iconpos="right" data-transition="flip">กลับ</a>        
    </div><!-- /header -->

    <div data-role="content">	
        <?php
//print_r($_GET);
//die();
//Array ( [q] => newsSearch [news_search] => sea [news_type] => 0 ) 
        ?>

        <ul data-role="listview">
            <?php
            $numRow = 0;
            $sql = 'SELECT * FROM news WHERE ';

            if($_GET['news_type'] == 0)
            {
                $sql .='name like "%' . $db->antihack($_GET['news_search']) . '%"';
                $numRow = $db->num_rows('news', 'id', 'name like "%' . $db->antihack($_GET['news_search']) . '%" ');
            }
            else
            {
                $sql .='ntype = ' . $db->antihack($_GET['news_type']) . ' AND name like "%' . $db->antihack($_GET['news_search']) . '%"';
                $numRow = $db->num_rows('news', 'id', ' ntype = ' . $db->antihack($_GET['news_type']) . ' AND name like "%' . $db->antihack($_GET['news_search']) . '%" ');
            }
            $sql .= '  ORDER BY id DESC LIMIT 20 ';
            //echo $numRow;
            /// echo $sql;
            //die();
            $res = $db->select_query($sql);
            //die(print_r($sql));
            if($numRow > 0)
            {
                while($arr = $db->fetch($res))
                {
                    $countReply = $db->num_rows('news_reply', 'reply_id', 'news_id = ' . $arr['id'] . '');
                    ?>
                    <li data-ctype="newsSearch" data-wordsearch='<?php echo $_GET['news_search']; ?>' data-newstype='<?php echo $_GET['news_type']; ?>' id="news_<?php echo $arr['id']; ?>" last_id="<?php echo $arr['id']; ?>">
                        <a rel="external" href="?q=newsDetail&newsId=<?php echo $arr['id']; ?>">
                            <img src="images/1351593888_small.jpg" alt="" width="80" height="80" />
                            <h3><?php echo $arr['name']; ?></h3>
                            <p><?php echo $arr['name'] . '-' . $arr['id'] . ' ->' . $_GET['news_search']; ?></p>
                            <span class="ui-li-count ui-btn-up-c ui-btn-corner-all"><?php echo $countReply; ?></span>
                        </a> 
                    </li>
                    <?php
                }
            }
            else
            {
                ?>
                <li>
                    <h3>--  ไม่พบข้อมูลในระบบ --</h3>
                </li>
                <?php
            }
            ?>
        </ul>
        <?php
        $numReply = $db->rows($res);
        if($numReply != 0)
        {
            ?>
            <div id="loadding-text" style="clear:both;" align="center">&nbsp;</div>  
            <div id="loading" align="center"></div>
            <?php
        }
        ?> 

    </div><!-- /content -->

    <div data-role="footer" >
        <h4>Version 1.0 Beta</h4>
        <a id="link_web" href="http://www.mocyc.com" data-icon="refresh" data-iconpos="right" class="ui-btn-right">แบบปกติ</a>

    </div><!-- /footer -->
</div><!-- /page -->

</body>
</html>